using System;
using System.Drawing;

namespace MDAControlsFramework.Helpers {
	public sealed class GradientFill {
		public static bool Fill(Graphics gr, Rectangle rc, MDAGradientStruct gradient) {
			return GradientFill.Fill(gr, rc, gradient.startColor, gradient.endColor, gradient.fillDir);
		}

		public static bool Fill(Graphics gr, Rectangle rc, Color startColor, Color endColor, FillDirection fillDir) {
			Win32Helper.TRIVERTEX[] pVertex = new Win32Helper.TRIVERTEX[] {
			                                                              		new Win32Helper.TRIVERTEX(rc.X, rc.Y, startColor), new Win32Helper.TRIVERTEX(rc.Right, rc.Bottom, endColor)
			                                                              };

			Win32Helper.GRADIENT_RECT[] pMesh = new Win32Helper.GRADIENT_RECT[] {
			                                                                    		new Win32Helper.GRADIENT_RECT(0, 1)
			                                                                    };

			IntPtr hdc = gr.GetHdc();
			bool flag = Win32Helper.GradientFill(hdc, pVertex, (uint)pVertex.Length, pMesh, (uint)pMesh.Length, (uint)fillDir);
			gr.ReleaseHdc(hdc);
			return flag;
		}

		public enum FillDirection {
			LeftToRight,
			TopToBottom
		}
	}
}